package org.yaac.shared.property;

import static com.google.common.collect.Lists.newLinkedList;
import static com.google.common.collect.Maps.newHashMap;

import java.util.List;
import java.util.Map;




/**
 * @author Max Zhu (thebbsky@gmail.com)
 *
 */
public enum PropertyType {
	NULL("none", NullPropertyInfo.class), 
	LONG("long", LongPropertyInfo.class),
	DOUBLE("double", DoublePropertyInfo.class),
	BLOB_KEY("blob key", BlobKeyPropertyInfo.class),
	BLOB("blob", BlobPropertyInfo.class),
	TIMESTAMP("datetime", DatePropertyInfo.class), 
	STRING("string", StringPropertyInfo.class),
	TEXT("text", TextPropertyInfo.class),
	BOOL("bool", BooleanPropertyInfo.class),
	KEY("key", KeyInfo.class), 
	USER("user", UserPropertyInfo.class),
	GEOPT("geo pt", GeoPtPropertyInfo.class),
	IM_HANDLE("im handle", IMHandlePropertyInfo.class),
	LIST("list", ListPropertyInfo.class),
	SHORT_BLOB("short blob", ShortBlobPropertyInfo.class),
	POSTTAL_ADDRESS("postal address", PostalAddressPropertyInfo.class),
	PHONE_NO("phone number", PhoneNumberPropertyInfo.class),
	LINK("link", LinkPropertyInfo.class),
	EMAIL("email", EmailPropertyInfo.class),
	CATEGORY("category", CategoryPropertyInfo.class);
	
	private String representation;

	private Class<? extends PropertyInfo> infoClass;
	
	private PropertyType(String representation, Class<? extends PropertyInfo> infoClass) {
		this.representation = representation;
		this.infoClass = infoClass;
	}

	public String getRepresentation() {
		return representation;
	}

	public Class<? extends PropertyInfo> getInfoClass() {
		return infoClass;
	}
	
	// representation list
	private static final List<String> representations = newLinkedList();
	
	// class to type mapping
	private static final Map<Class<? extends PropertyInfo>, PropertyType> typeMap = newHashMap();
	
	// init 
	static {
		for (PropertyType propType : PropertyType.values()) {
			typeMap.put(propType.infoClass, propType);
			representations.add(propType.representation);
		}
	}
	
	public static List<String> allRepresentations() {
		return representations;
	}
	
	public static PropertyType typeOf(PropertyInfo info) {
		return typeMap.get(info.getClass());
	}
}